package com.currency.mall.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.Button;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.currency.mall.R;
import com.currency.mall.entity.SharesRoyalty;

import java.util.List;

/**
 * Created by Administrator on 2018/12/5.
 */

public class GoldRateTermAdapter extends BaseQuickAdapter<SharesRoyalty, BaseViewHolder> {

    private int selectedIndex;        //记录当前选中的条目索引
    public void setSelectedIndex(int position) {
        this.selectedIndex = position;
        notifyDataSetChanged();
    }

    public GoldRateTermAdapter(@Nullable List<SharesRoyalty> data, Context context) {
        super(R.layout.item_gold_rate_term, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SharesRoyalty sharesRoyalty) {
        TextView tvTerm = helper.getView(R.id.btn_term);
        if(helper.getAdapterPosition() == selectedIndex){
            tvTerm.setBackgroundResource(R.drawable.red_bg);
            tvTerm.setTextColor(Color.parseColor("#FFFFFF"));
        }else{
            tvTerm.setBackgroundResource(R.drawable.red_write_bg);
            tvTerm.setTextColor(Color.parseColor("#E51C23"));
        }
        if("DAY".equals(sharesRoyalty.getType())){
            tvTerm.setText(sharesRoyalty.getVal()+"天");
        }else  if("WEEK".equals(sharesRoyalty.getType())){
            tvTerm.setText(sharesRoyalty.getVal()+"周");
        }else  if("MONTH".equals(sharesRoyalty.getType())){
            tvTerm.setText(sharesRoyalty.getVal()+"月");
        }

    }

}
